import { _decorator, Component, Node, Label } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('RecordItem')
export class RecordItem extends Component {

    @property(Label)
    private title: Label = null;

    @property(Label)
    private time: Label = null;
    


    public setData(time:number, title:string = '道具积分+200') {
        if(time){
            // time 1748836064 转为时间格式， 时间戳为秒单位
            const date = new Date(time * 1000);
            const year = date.getFullYear();
            const month = date.getMonth() + 1; // getMonth() 返回 0-11
            const day = date.getDate();

            // 获取小时、分钟和秒
            const hours = date.getHours();
            const minutes = date.getMinutes();
            const seconds = date.getSeconds();

            // 格式化为 24 小时制
            const timeString =  `${year}-${month}-${day} ${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`;

            this.time.string = timeString;

            // 取出time的时分秒
            this.title.string = title + " ("+hours+minutes+seconds+")" ;
        }
       
    }

  
}


